package com.jic.purchase.service.impl;

import java.lang.Long;
import java.util.List;

import com.github.pagehelper.PageHelper;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.Page;

import com.jic.purchase.mapper.PurchaseOrderProductOperationMapper;
import com.jic.purchase.model.entity.PurchaseOrderProduct;
import com.jic.purchase.model.entity.PurchaseOrderProductOperation;
import com.jic.purchase.service.PurchaseOrderProductOperationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 采购单商品收货、发货记录表；
 * @author :
 * @email :
 * @since : 2020-09-20 09:25:21
 * @version : v1.0.0
 */
@Service
public class PurchaseOrderProductOperationServiceImpl implements PurchaseOrderProductOperationService {

    private PurchaseOrderProductOperationMapper purchaseOrderProductOperationMapper;

    @Override
    public long insert(PurchaseOrderProductOperation purchaseOrderProductOperation) {
        return purchaseOrderProductOperationMapper.insert(purchaseOrderProductOperation);
    }

    @Override
    public long delete(Long id) {
        return purchaseOrderProductOperationMapper.deleteByPrimaryKey(id);
    }

    @Override
    public long update(PurchaseOrderProductOperation purchaseOrderProductOperation) {
        return purchaseOrderProductOperationMapper.update(purchaseOrderProductOperation);
    }

    @Override
    public PurchaseOrderProductOperation queryByPrimaryKey(Long id){
        return purchaseOrderProductOperationMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<PurchaseOrderProductOperation> query(PurchaseOrderProductOperation purchaseOrderProductOperation){
        return purchaseOrderProductOperationMapper.listPageBySelective(purchaseOrderProductOperation);
    }

    @Override
    public PageResult<PurchaseOrderProductOperation> queryPage(PurchaseOrderProductOperation purchaseOrderProductOperation, Page pageQuery) {
        PageHelper.startPage(pageQuery.getStart(), pageQuery.getLimit());
        PageHelper.orderBy(" create_time desc");
        Long count = purchaseOrderProductOperationMapper.listPageBySelectiveCount(purchaseOrderProductOperation);
        List<PurchaseOrderProductOperation> responseList = purchaseOrderProductOperationMapper.listPageBySelective(purchaseOrderProductOperation);
        PageResult<PurchaseOrderProductOperation> result = new PageResult<>();
        result.setTotal(count);
        result.setRows(responseList);
        return  result;
    }

    @Autowired
    public void setPurchaseOrderProductOperationMapper(PurchaseOrderProductOperationMapper purchaseOrderProductOperationMapper) {
        this.purchaseOrderProductOperationMapper = purchaseOrderProductOperationMapper;
    }
}